#
# local settings not handled by libgist-provided generic config scripts
#

"""This file defines various functions and variables meant to be edited
by end-users to match their particular requirements.

The libgist codebase ships with several Python modules to help configure
the libgist driver program. These modules attempt to implement a
reasonably general and portable config system. However, some settings and
policies cannot be specified in advance and must be configured by
end-users. These local settings are defined in this module.

To setup the libgist driver program to function properly on your machine,
you should copy the Python config modules that come with libgist under
your home directory into the .gist and .gist/conf subdirectories and then
edit this file, viz., ~/.gist/conf/local_settings.py, to match your
particular setup.

Please note that you do not have to use the configuration modules that
come with libgist. You may, if you prefer, implement your own Python
config scripts. However, using the libgist-provided configuration system
and editing this file may prove to be a quicker and easier way to setup
libgist rather than starting from scratch."""

#---------------------------- ADMINISTRIVIA -----------------------------

# This file is part of libgist.
#
# libgist is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# libgist is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with libgist; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# REVISION HISTORY
#
# $HeadURL: http://libgist.googlecode.com/svn/branches/wu_dev/conf/conf/local_settings.py $
# $Id: local_settings.py 164 2012-02-23 09:23:21Z christian.g.siagian@gmail.com $

#------------------------------- IMPORTS --------------------------------

# Python standard library
import os, socket

#------------------------------ FUNCTIONS -------------------------------

# Where is the data stored?
def dataset_root(dataset_name):
   """This function specifies the top-level directory under which
different libgist datasets are stored.

This function is passed the name of the dataset specified on the command
line. This name may be a label that you then convert to a full path or it
may already be a full path to a top-level directory containing training
and testing images. The libgist developers regard the dataset name to be
the name of a directory under a top-level directory containing libgist
datasets. However, you may prefer to organize datasets, etc. in a
different way. Thus, what the dataset name represents is entirely up to
you.

Whatever your preferred organizational structure and connotation for
dataset names may be, this function should return the full path to a
top-level directory containing the data identified by the dataset_name
input variable.

The original values coded here are for the dataset locations used by the
libgist developers on the different machines on which they test. You
should either add your host name and data directory to the host_map
variable or simply remove it and return the appropriate directory
name."""

   # Mapping between hostname and location under user's home directory
   # where gist datasets may be found.
   host_map = {'netbook' : '/academics/usc/research/gist/data/',
               'ilab8'   : '/gist/data/',
               'iCore'   : '/gist/data/',
               'iRock'   : '/gist/data/',
               'evo-manu': '/ilab/gist-data/'}

   # Return full path to root directory containing datasets. Note that we
   # assume the dataset name is simply a subdirectory under the directory
   # specified by the above variable. You may prefer a different
   # approach.
   #return os.environ['HOME'] + host_map[socket.gethostname()] + dataset_name
   return "/lab/mviswana/gist/data/" + dataset_name

# What are the different category labels?
def categories(dataset_name):
   """This function returns a list of strings denoting the different
image categories.

The dataset_name input variable contains the dataset name command line
argument passed to the libgist driver program. We consider this name to
be an identifier that we "convert" to full pathnames, etc. You may wish
to do it differently.

In our case, the dataset name is used as a key that points to a list of
category labels. During development, we used a subset of the Caltech 256
dataset for testing. The category labels returned by this function are
simply subdirectories under the Caltech 256 root directory.

In your case, the dataset name may represent something other than a key.
Whatever your preferred connotation for this variable, this function is
expected to return a list of category labels that are used by libgist for
training and classification."""

   # We use the dataset name as a key that indexes different lists of
   # category labels. You, of course, may choose a different approach.
   #cat_map = {'caltech-256': ['008.bathtub',          '010.beer-mug',
                              #'033.cd',               '039.chopsticks',
                              #'046.computer-monitor', '058.doorknob',
                              #'159.people',           '195.soda-can',
                              #'229.tricycle',         '257.clutter']}


   cat_map = {'caltech-256': ['008.bathtub', '159.people']}

   return cat_map[dataset_name]

# Scale factor for num CPU's to decide on how many threads to launch
def num_threads_scaler():
   """Wherever and whenever feasible, libgist and its driver program
parallelize various operations and run them in multiple threads. Rather
than hard-coding the number of threads to use in the libgist codebase, we
prefer that end-users specify the number of threads to use.

In general, we use the available number of CPU's as a base number and
then multiply it by the number returned by this function to obtain the
final number. If this function returns 1 (one), libgist will launch as
many threads as there are CPU's. If it returns 2, libgist will use twice
the number of threads as there are CPU's. So on and so forth.

Note that this function can return a fractional number as well. For
example, returning 0.5 will result in libgist using half the number of
CPU's as the number of threads. This might be desirable on large compute
nodes shared by many people where you might want to leave some CPU's to
your colleagues.

It would be a bad idea to have this function return a number <= 0.
However, the libgist code does include a test to ensure that it uses at
least one thread.

The default implementation of this function is keyed to the hosts
libgist's developers usually work on. You may simply add your hostname
and scaler to it or replace the entire function with whatever suits you
best."""

   # Mapping between hostname and suitable scalers; add your hostname
   # here, replace all these entries with hostnames and scalers that make
   # sense in your situation, or just replace all the code in this
   # function with something more suitable for your needs.
   host_map = {'netbook' : 1,
               'ilab8'   : 1,
               'iCore'   : 1,
               'iRock'   : 1,
               'evo-manu': 1,
               'iRoll'   : 1 }
   return 1#host_map[socket.gethostname()]

#------------------------------------------------------------------------

# So things look consistent in everyone's emacs...
# Local Variables:
# indent-tabs-mode: nil
# End:
